package com.shr.xsunmvc.db;

import java.util.Map;

/**
 * 数据库表属性类
 * @author sun haoran
 *
 */
public class Table {
	/**
	 * 表名称
	 */
	private String name ;
	/**
	 * 主键名
	 */
	private String[] primaryKey ;
	/**
	 * 列类型
	 */
	private Map<String, Class<?>> columnTypeMap ;
	
	/**
	 * 对应的model
	 */
	private Class<? extends Model> modelClazz ;
	
	public Table(String name, Class<? extends Model> modelClazz){
		this.name = name ;
		this.modelClazz = modelClazz ;
	}

	public Table(String tableName, String primaryKey, Class<? extends Model> clazz) {
		this.name = tableName ;
		this.primaryKey = primaryKey.split(",") ;
		this.modelClazz = clazz ;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String[] getPrimaryKey() {
		return primaryKey;
	}

	public void setPrimaryKey(String[] primaryKey) {
		this.primaryKey = primaryKey;
	}

	public Map<String, Class<?>> getColumnTypeMap() {
		return columnTypeMap;
	}

	public void setColumnTypeMap(Map<String, Class<?>> columnTypeMap) {
		this.columnTypeMap = columnTypeMap;
	}

	public Class<? extends Model> getModelClazz() {
		return modelClazz;
	}

	public void setModelClazz(Class<? extends Model> modelClazz) {
		this.modelClazz = modelClazz;
	}
	
	/**
	 * is the table has the comlumLabel
	 * @param columnLabel
	 * @return
	 */
	public boolean hasColumnLabel(String columnLabel) {
		return columnTypeMap.containsKey(columnLabel);
	}
	
}
